DROP TRIGGER IF EXISTS dbo.Update_Disposition_Status_Trigger;  -- SQL Server 2016+



SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER dbo.Update_Disposition_Status_Trigger
    ON dbo.iws_disposition
    AFTER UPDATE
    AS
BEGIN
    SET NOCOUNT ON;
    -- 只处理status字段发生变化的记录
    IF UPDATE(status)
        BEGIN
            -- 批量更新iws_store_outside表的status字段
            UPDATE so
            SET so.status = i.status
            FROM dbo.iws_store_outside so
                     INNER JOIN inserted i
                                ON so.id = i.location  -- 使用指定的关联字段
                     INNER JOIN deleted d
                                ON i.id = d.id
            WHERE i.status != d.status;  -- 确保状态值确实发生了变化
        END
END
GO



SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER dbo.Update_Outside_Status_Trigger
    ON dbo.iws_store_outside
    AFTER UPDATE
    AS
BEGIN
    SET NOCOUNT ON;
    -- 只处理status字段发生变化的记录
    IF UPDATE(status)
        BEGIN
            -- 批量更新iws_store_outside表的status字段
            UPDATE do
            SET do.status = so.status
            FROM dbo.iws_disposition do
                     INNER JOIN inserted so
                                ON do.location = so.id  -- 使用指定的关联字段
                     INNER JOIN deleted d
                                ON so.id = d.id
            WHERE so.status != d.status;  -- 确保状态值确实发生了变化
        END
END
GO